/**
 * @Description: test
 * @Author: Hu Outstanding
 * @Date: 2022/2/23 15:02
 */
package com.aaa.three.util;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class LoginFilterUtil {
    public static void haha(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse resp = (HttpServletResponse) servletResponse;


        String contextPath = req.getContextPath();
        String requestURI = req.getRequestURI();

        String path = requestURI.replace(contextPath, "");

        String[]  pass = {
                "/",
                "/index.html",
                "/admin/login",
                "/admin/adminIndex.html",
                "/doctor/registered.html",
                "/doctor/erro.html",
                "/doctor/return-success.html",
                "/hang/listDepTwo",
                "/sch/getSch",
                "/reg/get",
                "/reg/getInfo",
                "/reg/play",
                "/hang/lisDepOne",
                "/reg/listAll"
        };
        List<String> passList = Arrays.asList(pass);

        if(   ! passList.contains( path )  ){
            Object admin = req.getSession().getAttribute("admin");
            if(admin == null){
                resp.sendRedirect("/demo/admin/adminIndex.html");
                return;
            }
        }
        filterChain.doFilter(req,resp);
    }
}
